#define _WIN32_DCOM
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
#include "Component\component.h"

void main()
{
	CoInitialize(NULL);

	IBindCtx* pBindCtx;
	CreateBindCtx(0, &pBindCtx);

	ULONG eaten;
	IMoniker* pMoniker;

	// Replace MyHost with machine name on which the component is registered
	OLECHAR string[] = L"host:MyHost!clsid:10000013-0000-0000-0000-000000000001";

	HRESULT hr = MkParseDisplayName(pBindCtx, string, &eaten, &pMoniker);
	if(FAILED(hr))
		cout << "MkParseDisplayName failed" << endl;

	IPrimeFactory* pPrimeFactory;
	pMoniker->BindToObject(pBindCtx, NULL, IID_IPrimeFactory, (void**)&pPrimeFactory);

	IPrime* pPrime;
	pPrimeFactory->CreatePrime(11, &pPrime);

	int next;
	pPrime->GetNextPrime(&next);
	cout << next << endl;

	OLECHAR* moniker_name;
	pMoniker->GetDisplayName(pBindCtx, NULL, &moniker_name);
	wprintf(L"DisplayName is %s\n", moniker_name);
	CoTaskMemFree(moniker_name);

	pPrime->Release();
	pPrimeFactory->Release();
	pBindCtx->Release();
	pMoniker->Release();

	CoUninitialize();
}